Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass Backend Object to Postprocessing Pipeline #304

Closed
wants to merge 3 commits into from

Conversation

Mat0vu
Copy link
Contributor

@Mat0vu Mat0vu commented Nov 12, 2024

Hi everyone,

following my Pull Request to add a postprocessing template for the siem_rule_ndjson format for the Elasticsearch backend (SigmaHQ/pySigma-backend-elasticsearch#94) I want to propose some minor changes here to enable the QueryTemplateTransformation to access variables that are managed by the backend directly. For this, the backend object is passed to the Jinja render functionality. I´ve seen on Discord that this functionality was also discussed there.

How to use the new Functionality:
In a postprocessing pipeline when using the QueryTemplateTransformation, variables managed by the backend can be accessed for example by {{ backend.variable1 }}.

One unit test was adjusted to check if the access is working correctly.

The backend object is handed over to all postprocessing transformations inside the apply function, however currently only QueryTemplateTransformation uses the backend reference whereas the rest of the transformations do not use it because I thought that this might be the most common use case. Do you think that the other transformations should also implement some handling with this new reference?

Thank you for the great project and feel free to comment and edit :)

@thomaspatzke
Copy link
Member

Hi! The last days I've done exactly the opposite and removed the pipeline parameter from all conditions, transformations etc 😉 The intention of this long planned change was to make the apply methods function signature more concise and increasing the codes efficiency by avoiding to pass the same object all the way around. Furthermore, the change prevents to switch pipelines while a conversion runs, which could cause inconsistent results. The new way to pass the pipeline is by doing this once with the set_pipeline() method. It also ensures that the pipeline is only set once while the lifetime and raises an exception if this is done twice.

There are also already existing possibilities for this use case:

  1. The backend can inject anything into ProcessingPipeline.state including functions. From there, it is accessible from the template via the pipeline.state variable.
  2. Similarly, the backend can also set SigmaRuleBase.custom_attributes, which is accessible with rule.custom_attributes from the template.

Since there are already possibilities to implement the specific use case and the pull request is conflicting with the recent refactoring, I reject the pull request, sorry for that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants